package likou;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/06/05 07:22
 */
public class _8 {
    public static void main(String[] args) {
        System.out.println(myAtoi("-91283472332"));
    }
    public static int myAtoi(String s) {
        s = s.trim();
        char[] scs = s.toCharArray();
        int zf = 1;
        boolean zfb = true;
        int now = 0;
        for(int i=0;i<scs.length;i++){
            if(zfb&&(scs[i]=='-'||scs[i]=='+')){
                if(scs[i]=='-'){
                    zf = -1;
                }
                zfb = false;
                continue;
            }
            System.out.println(scs[i]);
            if(!is_num(scs[i])){
                break;
            }
            int n = now;
            now = now*10+ (scs[i]-'0') *zf;
            if (Math.abs(n)>Math.abs(now)){
                if (zf>0){
                    return Integer.MAX_VALUE;
                }else {
                    return Integer.MIN_VALUE;
                }
            }
        }
        return now;

    }
    public static boolean is_num(char c){
        return (c-'0'>=0)&&(c-'0')<=9;
    }
}
